@page "/privacyMode"
@inherits ImportantComponentBase

<MyAppBar Title="@(I18n.T("Privacy mode"))"
          OnClick="NavigateToBack">
</MyAppBar>

@if (_isRender)
{
    <ScrollContainer>
        <MCard Class="my-list-card"
               Elevation="0"
               Rounded="@("lg")">
            <MList>
                <MListItem>
                    <MListItemIcon>
                        <MIcon Class="evident-icon">
                            menu_open
                        </MIcon>
                    </MListItemIcon>
                    <MListItemContent>
                        <MListItemTitle>
                            @(I18n.T("The display is set to private"))
                        </MListItemTitle>
                        <MListItemSubtitle Class="text-caption-xs-only">
                            @(I18n.T("Show the Set Private option in the diary menu"))
                        </MListItemSubtitle>
                    </MListItemContent>
                    <MListItemAction>
                        <SettingSwitch @bind-Value="showSetPrivacyDiary"
                                       SettingKey="@nameof(Setting.SetPrivacyDiary)">
                        </SettingSwitch>
                    </MListItemAction>
                </MListItem>

                <MDivider Class="mx-5"></MDivider>

                <MListItem>
                    <MListItemIcon>
                        <MIcon Class="evident-icon">
                            dark_mode
                        </MIcon>
                    </MListItemIcon>
                    <MListItemContent>
                        <MListItemTitle>
                            @(I18n.T("Enable dark mode"))
                        </MListItemTitle>
                        <MListItemSubtitle Class="text-caption-xs-only">
                            @(I18n.T("Enable dark mode when entering privacy mode"))
                        </MListItemSubtitle>
                    </MListItemContent>
                    <MListItemAction>
                        <SettingSwitch @bind-Value="enablePrivacyModeDark"
                                       SettingKey="@nameof(Setting.PrivacyModeDark)">
                        </SettingSwitch>
                    </MListItemAction>
                </MListItem>
            </MList>
        </MCard>

        <MCard Class="my-list-card"
               Elevation="0"
               Rounded="@("lg")">
            <MList>
                <MListItem>
                    <MListItemIcon>
                        <MIcon Class="evident-icon">
                            mdi:mdi-location-enter
                        </MIcon>
                    </MListItemIcon>
                    <MListItemContent>
                        <MListItemTitle>
                            @(I18n.T("Hide default entry"))
                        </MListItemTitle>
                        <MListItemSubtitle Class="text-caption-xs-only">
                            @(I18n.T("After hiding, it can be accessed through function search, which is located in the upper right corner of the \"Mine\" page"))
                        </MListItemSubtitle>
                    </MListItemContent>
                    <MListItemAction>
                        <MSwitch @bind-Value="hidePrivacyModeEntrance"
                                 TValue="bool"
                                 Readonly="true"
                                 OnClick="SwitchHidePrivacyModeEntrance"
                                 Dense="true"
                                 Inset="true"
                                 Color="white">
                        </MSwitch>
                    </MListItemAction>
                </MListItem>

                <MDivider Class="mx-5"></MDivider>

                @if (hidePrivacyModeEntrance)
                {
                    <MListItem OnClick="() => showPrivacyModeFunctionSearchKeyDialog = true">
                        <MListItemIcon>
                            <MIcon Class="evident-icon">
                                keyboard
                            </MIcon>
                        </MListItemIcon>
                        <MListItemContent>
                            <MListItemTitle>
                                @(I18n.T("Custom search keywords"))
                            </MListItemTitle>
                            <MListItemSubtitle Class="text-caption-xs-only">
                                @(I18n.T("Enter keywords in the feature search to display privacy mode"))
                            </MListItemSubtitle>
                        </MListItemContent>
                        <MListItemContent Class="setting-item-state">
                            <MListItemSubtitle Class="font-weight-bold">
                                @privacyModeFunctionSearchKey
                            </MListItemSubtitle>
                        </MListItemContent>
                        <MListItemAction>
                            <MIcon>chevron_right</MIcon>
                        </MListItemAction>
                    </MListItem>
                }
                else
                {
                    <MListItem OnClick="() => showPrivacyModeEntrancePasswordDialog = true">
                        <MListItemIcon>
                            <MIcon Class="evident-icon">
                                key
                            </MIcon>
                        </MListItemIcon>
                        <MListItemContent>
                            @(I18n.T("Set default entry password"))
                        </MListItemContent>
                        <MListItemContent Class="setting-item-state">
                            <MListItemSubtitle>
                                @PrivacyModeEntrancePasswordSetStateText
                            </MListItemSubtitle>
                        </MListItemContent>
                        <MListItemAction>
                            <MIcon>chevron_right</MIcon>
                        </MListItemAction>
                    </MListItem>
                }
            </MList>
        </MCard>

        @if (Desktop)
        {
            <MCard Class="my-list-card"
                   Elevation="0"
                   Rounded="@("lg")">
                <MListItem OnClick="SwitchPrivacyMode">
                    <MListItemIcon>
                        <MIcon Class="evident-icon">
                            swap_horiz
                        </MIcon>
                    </MListItemIcon>
                    <MListItemContent>
                        @(I18n.T(SwitchPrivacyModeText))
                    </MListItemContent>
                    <MListItemAction>
                        <MIcon>chevron_right</MIcon>
                    </MListItemAction>
                </MListItem>
            </MCard>
        }

        <MCard Class="my-list-card"
               Elevation="0"
               Rounded="@("lg")">
            <MListItem OnClick="MoveOldPrivacyDiaries">
                <MListItemIcon>
                    <MIcon Class="evident-icon">
                        mdi:mdi-file-move-outline
                    </MIcon>
                </MListItemIcon>
                <MListItemContent>
                    <MListItemTitle>
                        @(I18n.T("Move the old version of Privacy Diary"))
                    </MListItemTitle>
                    <MListItemSubtitle Class="text-caption-xs-only">
                        @(I18n.T("Move the data from the old version of the privacy diary to the new version"))
                    </MListItemSubtitle>
                </MListItemContent>
                <MListItemAction>
                    <MIcon>chevron_right</MIcon>
                </MListItemAction>
            </MListItem>
        </MCard>

        <MAlert Class="mb-5 text-subtitle-2 text--secondary text-pre-wrap"
                Elevation="0"
                Rounded="@("lg")"
                Icon="@("info")">
            @(I18n.T("Privacy mode data from version 1.3.9 and earlier will be automatically migrated to the new version of privacy mode after the update. \nIf the old privacy data is obtained by restoring backups or importing, it will be displayed together with the regular diary. Please click the migration button above to move them to privacy mode."))
        </MAlert>
    </ScrollContainer>

    @if (Mobile)
    {
        <MContainer Fluid>
            <MButton Class="black-white-btn mb-2"
                     Rounded="true"
                     Block="true"
                     Large="true"
                     OnClick="SwitchPrivacyMode">
                @(I18n.T(SwitchPrivacyModeText))
            </MButton>
        </MContainer>
    }

    <InputDialog @bind-Visible="showPrivacyModeFunctionSearchKeyDialog"
                 Text="@privacyModeFunctionSearchKey"
                 Title="@(I18n.T("Custom search keywords"))"
                 Placeholder="@(I18n.T("Please enter keywords"))"
                 OnOK="SavePrivacyModeSearchKey">
    </InputDialog>

    <PasswordDialog @bind-Visible="showPrivacyModeEntrancePasswordDialog"
                    Title="@(I18n.T("Set default entry password"))"
                    MaxLength="20"
                    OnOK="SetPassword">
    </PasswordDialog>

    <CustomMDialog @bind-MyValue="showHidePrivacyModeEntranceConfirmDialog"
                   ContentClass="rounded-lg"
                   MaxWidth="420">
        <MCard>
            <MCardTitle Class="font-weight-bold">
                @(I18n.T("Hide default entry"))
                <MSpacer></MSpacer>
                <MButton Icon="true"
                         OnClick="@(() => showHidePrivacyModeEntranceConfirmDialog = false)">
                    <MIcon>close</MIcon>
                </MButton>
            </MCardTitle>
            <MCardText Class="pb-0">
                <div>
                    @(I18n.T("After hiding, it can be accessed through function search, which is located in the upper right corner of the \"Mine\" page"))
                </div>
                <div>
                    @(I18n.T("Enter keywords in the feature search to display privacy mode"))
                </div>
                <div class="d-flex align-end">
                    @(I18n.T("Current key"))
                    <div class="font-weight-bold text-h6 ml-2">@privacyModeFunctionSearchKey</div>
                </div>
            </MCardText>
            <MCardActions>
                <MSpacer></MSpacer>
                <MButton Text
                         OnClick="() => showHidePrivacyModeEntranceConfirmDialog = false">
                    @(I18n.T("Cancel"))
                </MButton>
                <MButton Text
                         Color="primary"
                         OnClick="ConfirmHidePrivacyModeEntrance">
                    @(I18n.T("OK"))
                </MButton>
            </MCardActions>
        </MCard>
    </CustomMDialog>
}
